//
//  XYJGLFrameModel.m
//  徙游记-01
//
//  Created by hcios on 2017/7/10.
//  Copyright © 2017年 鹿林. All rights reserved.
//

#import "XYJGLFrameModel.h"

#define TitleFont [UIFont systemFontOfSize:15]
#define ContextFont [UIFont systemFontOfSize:13]


@implementation XYJGLFrameModel

-(void)setModel:(XYJGLModel *)model{
    
    _model = model;
    CGFloat padding = 10;
    
    //标题
    if ([model.title isEqualToString:@""]) {
        self.titleFrame = CGRectZero;
    }else{
        CGSize titleSize = [self sizeWithText:model.title font:TitleFont maxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
        CGFloat titleW = titleSize.width;
        CGFloat titleH = titleSize.height;
        self.titleFrame = RECT_MAKE(padding, padding, titleW, titleH);
    }
    
    //文字
    if ([model.description isEqualToString:@""]) {
        self.contextFrame = RECT_MAKE(padding, CGRectGetMaxY(self.titleFrame)+5, 0, 0);
    }else{
        CGSize textSize = [self sizeWithText:model.gl_description font:ContextFont maxSize:CGSizeMake(SCREEN_WIDTH - padding * 2, MAXFLOAT)];
        self.contextFrame = CGRectMake(padding, CGRectGetMaxY(self.titleFrame)+5, textSize.width, textSize.height);
    }
    
    _cellHeight = CGRectGetMaxY(self.contextFrame) + padding * 2;
    
}



-(CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize
{
    NSDictionary *dict = @{NSFontAttributeName : font};
    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
}


@end
